import urllib.request
import lxml.etree as le

# 从URL获取HTML
response = urllib.request.urlopen('https://edu.csdn.net/')
html = response.read().decode('utf-8')
# 将HTML转换为XML
html_x = le.HTML(html)
# 获取class='showItem_conTop'的div节点
div_x_s = html_x.xpath('//div[@class="showItem_conTop"]')
# 遍历节点
for div_x in div_x_s:
    # 获取节点下的h4子节点text
    category1 = div_x.xpath('./h4/a/text()')[0]
    # 获取节点下的div子节点text
    category2 = div_x.xpath('./div/a/text()')
    # 输出大分类
    print(category1)
    for category2_sub in category2:
        # 输出小分类
        print('\t' + category2_sub)
